var express = require('express');
var router = express.Router();
const db = require('./db');
const crypto = require('crypto');

//设置跨域访问
router.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Credentials', true);
  res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With')
  res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS');
  res.header('Content-Type', 'application/json;charset=utf-8');
  next()
});
/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('respond with a resource');
});

// 管理信息
router.get('/a', function (req, res, next) {
        db("SELECT * FROM `sys_menu`", (error, data) => {
            res.json(data)
            console.log(data)
        })
});

router.post('/register', function (req, res, next) {
  const md5 = crypto.createHash('md5');
  const registMsg = req.body;
  const phone = registMsg.phone;
  // const user_pwd = registMsg.user_pwd;
  const user_name = registMsg.user_name;
  const user_pwd = md5.update(registMsg.pwd).digest('hex');
  // res.json(registMsg)
});

module.exports = router;
